package com.lkd.controller;

import com.lkd.entity.Business;
import com.lkd.entity.Node;
import com.lkd.result.Result;
import com.lkd.service.NodeService;
import com.lkd.service.VmService;
import com.lkd.vo.VmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class NodeController extends Result {

    @Autowired
    private NodeService nodeService;
    @Autowired
    private VmService vmService;

    //1.2.1 接口一：查询商圈列表
    @GetMapping("/api/vm-service/businessType")
    public Result getBusinessType() {
        List<Business> businessList = nodeService.getBusinessType();
        return success(businessList);
    }

    // 1.2.2 接口二：新增点位
    @PostMapping("/api/vm-service/node")
    public Result addNode(@RequestBody Node node) {
        boolean result = nodeService.addNode(node);
        if (result) {
            return success(result);
        } else {
            return error("新增点位失败");
        }
    }

    //1.3  获取点位详情(根据点位id查询设备列表)
    @GetMapping("/api/vm-service/node/vmList/{nodeId}")
    public Result findByNodeId(@PathVariable Long nodeId) {
        List<VmVo> vmVoList = vmService.findByNodeId(nodeId);
        return Result.success(vmVoList);
    }

    //1.4 修改点位
    @PutMapping("/api/vm-service/node")
    public Result updateNode(@RequestBody Node node) {
        boolean result = nodeService.updateNode(node);
        if (result) {
            return success(result);
        } else {
            return error("修改点位失败");
        }
    }

    //1.5 删除点位
    @DeleteMapping("/api/vm-service/node/{nodeId}")
    public Result deleteNode(@PathVariable("nodeId") Long nodeId) {
        boolean result = nodeService.deleteNode(nodeId);
        if (result) {
            return success(result);
        } else {
            return error("删除点位失败");
        }
    }
}
